package com.crawler.controller;


import com.crawler.config.CrawlerConfig;
import com.crawler.execute.DefaultCrawler;
import com.crawler.execute.DefaultCrawlerExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping(value="/crawler")
public class CrawlerController {

    @Autowired
    private DefaultCrawlerExecutor crawlerExecute;

    @Autowired
    private CrawlerConfig crawlerConfig;

    @Autowired
    private DefaultCrawler defaultCrawler;

    @ResponseBody
    @RequestMapping(value="/do")
    public String doTask() throws InterruptedException {
        defaultCrawler.addUrl(crawlerConfig.getStartUrls());
        for (int i=0;i<crawlerConfig.getThreadCount();i++){
            crawlerExecute.execute();
        }
        return "success";
    }
}